package org.stars.config;

public enum Message {
	DAOSTARS_CONFIG_DIR,
	DAOSTARS_START, 
	MESSAGES_LOAD, 
	SET_PARAMETER, 
	
	SOURCE_LOADER_01, 
	SOURCE_LOADER_02,
	SOURCE_LOADER_03,
	SOURCE_LOADER_04,
	
	SOURCE_FINDER_01,
	SOURCE_FINDER_02,
	SOURCE_FINDER_03,
	SOURCE_FINDER_04,
	
	TEMPLATE_PARSER_01,
	TEMPLATE_PARSER_02,
	
	TEMPLATE2_PARSER_01,
	TEMPLATE2_PARSER_02,
	
	MACRO_LOADER_01,
	MACRO_LOADER_02,
	MACRO_LOADER_03,
	MACRO_LOADER_04,
	
	TYPE_ALIAS_LOADER_01,
	TYPE_ALIAS_LOADER_02,
	TYPE_ALIAS_LOADER_03,
	
	SQL_MAPPER_IMPL_01,
	SQL_MAPPER_IMPL_02,
	
	/**
	 * During the parsing of sqlMapper, if found sqls with same id
	 */
	DUPLICATE_ID_FOUND_ERROR,
	
	MALFORMED_SQL_ERROR,
	MACRO_NOT_DEFINED_ERROR,
	SQL_NOT_DEFINED_ERROR,
	CIRCULAR_DEPENDENCY_ERROR,
	TYPE_ALIAS_ERROR, 
	
	SUBPARSER06_01_ERROR,
	
	/**
	 * Macro error
	 */
	MACRO_ERROR,
	MACRO_ARGS_REQUIRED_ERROR,
	MACRO_ARGS_NOT_ADMITTED_ERROR, 
	MACRO_BODY_REQUIRED_ERROR, 
	MACRO_BODY_NOT_ADMITTED_ERROR; 	

	private String key;

	private Message(String value) {
		this.key = value;
	}
	
	private Message()
	{
		key=super.toString();
	}

	@Override
	public String toString() {
		return with(new String[0]);
	}

	public String toString(Object... args) {
		return with(args);
	}

	public String toString(String... args) {
		return with(args);
	}

	public String with(Object... args) {

		String[] argz = new String[args.length];
		int i = 0;
		for (Object item : args) {
			argz[i] = item != null ? item.toString() : null;
			i++;
		}

		return with(argz);
	}

	public String with(String... args) {

		try {
			MessageBundle bundle = Config.getMessageBundle();

			if (args == null || args.length == 0) {
				return bundle.getMessage(key);
			}
			return bundle.getMessage(key, args);
		} catch (Exception e) {
			return "Error during message " + key+". Exception message ";
		}
	}

}
